package view;

/**
 * this is a JPanel to hold radio buttons for each of the Boundary's
 * this is extendable because if one were to add another type of Boundary, it is easy to add it into the 
 * GUI with the appropriate method
 * @author ga-youngjoung
 *
 */

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import utilities.*;

import Environment.Boundary;
import Environment.InfiniteBoundary;
import Environment.WallBoundary;

public class BoundaryPanel extends JPanel{
	
	private Canvas myView;
	private ButtonGroup wallGroup;
	
	public BoundaryPanel(Canvas view) {
		wallGroup = new ButtonGroup();
		myView = view;
	}
	
	
	/**
	 * this is the Action Listener that will change the boundary based on the class name 
	 * in the constructor
	 * @author ga-youngjoung
	 *
	 */
	public class AddBoundaryListener implements ActionListener {

		private String myClassName;
		
		public AddBoundaryListener(String className) {
			myClassName = className;
		}
		
		public void actionPerformed(ActionEvent e) {
			myView.getEnvironment().setBoundary((Boundary) Reflection.createInstance("Environment."+myClassName, myView.getEnvironment()));
		}
		
	}

    /**
     * this method will add the Boundary type to the GUI in the form of a radio button that is
     * part of a ButtonGroup
     * @param className - String form of the class name of the Boundary
     * @param title - title of the radio button on the GUI
     */
	public void addBoundaryType(String className, String title) {
		JRadioButton button = new JRadioButton(title);
		button.addActionListener(new AddBoundaryListener(className));
		wallGroup.add(button);
		add(button);
	}
	
	
	
}
